# -*- coding: utf-8 -*-

import socket,select
import time
host = "192.168.9.87"
port = 50000
try:
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((host,port))
    s.setblocking(False)
except Exception,e:
    print 1
    exit()
for i in xrange(5):
    flag = 0
    infds,outfds,errfds = select.select([s,],[s,],[],3)
    for out in outfds:
        try:
            out.send("client")
            print "send to server"
        except Exception, e:
            flag = 1
            continue
    for ind in infds:
        buf = ""
        try:
            buf = ind.recv(1024)
            print "recv" + buf
        except Exception, e:
            flag = 1
            continue
    if not flag:
        i = 0
    time.sleep(1)
s.close()
t.close()
